<?php
	function getDirectoryList ($directory)
	// lay danh sach file trong thu muc , tra ve mang
	{
		// create an array to hold directory list
		$results = array();
		// create a handler for the directory
		$handler = opendir($directory);
		// open directory and walk through the filenames
		while ($file = readdir($handler)) 
		{
		  // if file isn't this directory or its parent, add it to the results
		  if ($file != "." && $file != "..") 
		  {
			$results[] = $file;
		  }
		}
		// tidy up: close the handler
		closedir($handler);
		// done!
		return $results;
	}
?>
<?php
	function empty_forder($dir)
	// lam rong thu muc
	{
	    if(!$dh = @opendir($dir)) return;
	    while (false !== ($obj = readdir($dh))) {
	        if($obj=='.' || $obj=='..') continue;
	        if (!@unlink($dir.'/'.$obj)) empty_forder($dir.'/'.$obj, true);
	    }

	    closedir($dh);

	}
?>
<?php
	function create_file($file_name)
	{
		$ourFileName = "$file_name";
		$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
		fclose($ourFileHandle);
	}
	function chong_90($ten_file_anh)
	{
		if(ereg(".php",$ten_file_anh))
		{
			thongbao("ko dc up ten anh co chuoi ki tu '.php'");
			trangtruoc();
			exit();
		}
	}
	function thongbao($chuoi)
	{
		echo "<script>alert(\"$chuoi\");</script>";
	}
	function trangtruoc()
	{
		echo "
		<script type=\"text/javascript\">window.history.back();</script>";
	}
?>
<?php
	function them_vao_co_so_du_lieu_mot_dong()
	{
		chong_90($ten_file_anh);
		$c3="";
		if($_FILES['up_hinh_1']['name']!=""){chong_90($_FILES['up_hinh_1']['name']);$c3=$c3."____".$_FILES['up_hinh_1']['name'];}
		if($_FILES['up_hinh_2']['name']!=""){chong_90($_FILES['up_hinh_2']['name']);$c3=$c3."____".$_FILES['up_hinh_2']['name'];}
		if($_FILES['up_hinh_3']['name']!=""){chong_90($_FILES['up_hinh_3']['name']);$c3=$c3."____".$_FILES['up_hinh_3']['name'];}
		if($_FILES['up_hinh_4']['name']!=""){chong_90($_FILES['up_hinh_4']['name']);$c3=$c3."____".$_FILES['up_hinh_4']['name'];}
		if($_FILES['up_hinh_5']['name']!=""){chong_90($_FILES['up_hinh_5']['name']);$c3=$c3."____".$_FILES['up_hinh_5']['name'];}
		if($_FILES['up_hinh_6']['name']!=""){chong_90($_FILES['up_hinh_6']['name']);$c3=$c3."____".$_FILES['up_hinh_6']['name'];}
		if($_FILES['up_hinh_7']['name']!=""){chong_90($_FILES['up_hinh_7']['name']);$c3=$c3."____".$_FILES['up_hinh_7']['name'];}
		if($_FILES['up_hinh_8']['name']!=""){chong_90($_FILES['up_hinh_8']['name']);$c3=$c3."____".$_FILES['up_hinh_8']['name'];}
		if($_FILES['up_hinh_9']['name']!=""){chong_90($_FILES['up_hinh_9']['name']);$c3=$c3."____".$_FILES['up_hinh_9']['name'];}
		if($_FILES['up_hinh_10']['name']!=""){chong_90($_FILES['up_hinh_10']['name']);$c3=$c3."____".$_FILES['up_hinh_10']['name'];}
		if($_FILES['up_hinh_11']['name']!=""){chong_90($_FILES['up_hinh_11']['name']);$c3=$c3."____".$_FILES['up_hinh_11']['name'];}
		if($_FILES['up_hinh_12']['name']!=""){chong_90($_FILES['up_hinh_12']['name']);$c3=$c3."____".$_FILES['up_hinh_12']['name'];}
			$tv="select max(id) from dulieu";
			$tv_1=mysql_query($tv);
			$tv_2=mysql_fetch_row($tv_1);
			$id=$tv_2[0];
			$thu_muc="../hinhanh_flash/sanpham/$id/";
			mkdir($thu_muc);
			chmod($thu_muc, 0777);
			create_file($thu_muc."index.html");
			if($_FILES['up_hinh_1']['name']!=""){move_uploaded_file($_FILES['up_hinh_1']['tmp_name'],$thu_muc.$_FILES['up_hinh_1']['name']);}
			if($_FILES['up_hinh_2']['name']!=""){move_uploaded_file($_FILES['up_hinh_2']['tmp_name'],$thu_muc.$_FILES['up_hinh_2']['name']);}
			if($_FILES['up_hinh_3']['name']!=""){move_uploaded_file($_FILES['up_hinh_3']['tmp_name'],$thu_muc.$_FILES['up_hinh_3']['name']);}
			if($_FILES['up_hinh_4']['name']!=""){move_uploaded_file($_FILES['up_hinh_4']['tmp_name'],$thu_muc.$_FILES['up_hinh_4']['name']);}
			if($_FILES['up_hinh_5']['name']!=""){move_uploaded_file($_FILES['up_hinh_5']['tmp_name'],$thu_muc.$_FILES['up_hinh_5']['name']);}
			if($_FILES['up_hinh_6']['name']!=""){move_uploaded_file($_FILES['up_hinh_6']['tmp_name'],$thu_muc.$_FILES['up_hinh_6']['name']);}
			if($_FILES['up_hinh_7']['name']!=""){move_uploaded_file($_FILES['up_hinh_7']['tmp_name'],$thu_muc.$_FILES['up_hinh_7']['name']);}
			if($_FILES['up_hinh_8']['name']!=""){move_uploaded_file($_FILES['up_hinh_8']['tmp_name'],$thu_muc.$_FILES['up_hinh_8']['name']);}
			if($_FILES['up_hinh_9']['name']!=""){move_uploaded_file($_FILES['up_hinh_9']['tmp_name'],$thu_muc.$_FILES['up_hinh_9']['name']);}
			if($_FILES['up_hinh_10']['name']!=""){move_uploaded_file($_FILES['up_hinh_10']['tmp_name'],$thu_muc.$_FILES['up_hinh_10']['name']);}
			if($_FILES['up_hinh_11']['name']!=""){move_uploaded_file($_FILES['up_hinh_11']['tmp_name'],$thu_muc.$_FILES['up_hinh_11']['name']);}
			if($_FILES['up_hinh_12']['name']!=""){move_uploaded_file($_FILES['up_hinh_12']['tmp_name'],$thu_muc.$_FILES['up_hinh_12']['name']);}
	}
?>